﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Data.SqlClient;
using Enterprise.Logging;
using System.Reflection;

namespace Viewer.BusinessObject.BusinessEntities
{
    public partial class DataClassesDataContext
    {
        
        public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
        {
            try
            {
                ChangeSet changeSet = this.GetChangeSet();
                if (changeSet != null)
                {
                    string propertyValue = Enterprise.Core.CurrentContext.LoginName();
                    DateTime utcNow = DateTime.UtcNow;
                    foreach (object obj2 in changeSet.Inserts)
                    {
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj2, "IsDeleted", "0");
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj2, "InsAt", utcNow);
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj2, "UpdAt", utcNow);
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj2, "InsBy", propertyValue);
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj2, "UpdBy", propertyValue);

                    }
                    foreach (object obj3 in changeSet.Updates)
                    {
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj3, "UpdAt", utcNow);
                        //Enterprise.Utilities.ReflectionHelper.SetPropertyValue(obj3, "UpdBy", propertyValue);

                    }

                }
                base.SubmitChanges(failureMode);
            }
            catch (ChangeConflictException)
            {
                foreach (ObjectChangeConflict conflict in this.ChangeConflicts)
                {
                    conflict.Resolve(RefreshMode.KeepChanges);
                }
                base.SubmitChanges(ConflictMode.FailOnFirstConflict);
            }
            catch (SqlException exception)
            {
                Logger.Error(this, MethodBase.GetCurrentMethod().Name, exception.ToString());
                throw exception;
            }
        }
    }
}